import {
  Injectable,
  NestMiddleware,
  UnauthorizedException,
} from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

@Injectable()
export class AuthenticationMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction): void {
    console.log('登录拦截器...');
    const sysUser = req.session.user;
    if (!sysUser) {
      throw new UnauthorizedException('用户未登录');
    }
    next();
  }
}
